class MaximumTripletValue {
class Solution {
        public long maximumTripletValue(int[] nums) {
            int n = nums.length;
            long ans = 0;
            long dmax = 0;
             long imax = 0;
            for(int k = 0 ; k < n ; k++){
                ans = Math.max(ans, dmax * (long)nums[k]);
                dmax = Math.max(dmax, imax - (long)nums[k]);
                imax = Math.max(imax, (long)nums[k]);
            }
            return ans;
        }
}
}